package eCheque;

import java.io.Serializable;

/**
 * Class representing a response from an RPC call to the EChequeServer
 * 
 * @author Steve Pennington
 * 
 */
public class EChequeResponse implements Serializable {
	private static final long serialVersionUID = -4036501801972719739L;

	private String message;
	private Throwable error;
	private ResponseCode responseCode;

	public EChequeResponse(ResponseCode responseCode) {
		this(responseCode, null, null);
	}

	public EChequeResponse(ResponseCode responseCode, String message) {
		this(responseCode, message, null);
	}

	/**
	 * Create a response from the provided error. The response code will be set
	 * to {@link ResponseCode#ERROR} and the message will be set to
	 * {@link Throwable#getMessage()}.
	 * 
	 * This is equivalent to calling
	 * EChequeResponse#EChequeResponse(ResponseCode.ERROR, error.getMessage(),
	 * error)
	 * 
	 * @param error
	 *            Error to return to the client
	 */
	public EChequeResponse(Throwable error) {
		this(ResponseCode.ERROR, error.getMessage(), error);
	}

	public EChequeResponse(ResponseCode responseCode, String message,
			Throwable error) {
		this.setResponseCode(responseCode);
		this.setMessage(message);
		this.setError(error);
	}

	/**
	 * @param error
	 *            the error to set
	 */
	public void setError(Throwable error) {
		this.error = error;
	}

	/**
	 * @return the error
	 */
	public Throwable getError() {
		return error;
	}

	/**
	 * @param responseCode
	 *            the responseCode to set
	 */
	public void setResponseCode(ResponseCode responseCode) {
		this.responseCode = responseCode;
	}

	/**
	 * @return the responseCode
	 */
	public ResponseCode getResponseCode() {
		return responseCode;
	}

	/**
	 * @param message
	 *           the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}
}
